const { Sequelize } = require('sequelize');

const sequelize = new Sequelize('chat_db', 'root', 'a18967482169', {
    host: 'localhost',
    dialect: 'mysql',
    logging: console.log,
    pool: {
        max: 10,
        min: 2,
        acquire: 60000,
        idle: 20000
    },
    isolationLevel: Sequelize.Transaction.ISOLATION_LEVELS.READ_COMMITTED,
    retry: {
        max: 3,
        match: [
            /Deadlock/i,
            /ER_LOCK_DEADLOCK/
        ]
    }
});

// 测试数据库连接
async function testConnection() {
    try {
        await sequelize.authenticate();
        console.log('数据库连接成功');
    } catch (error) {
        console.error('数据库连接失败:', error);
    }
}

testConnection();

module.exports = sequelize; 